
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
 */
package nac.firefight;

//~--- JDK imports ------------------------------------------------------------

import java.beans.XMLDecoder;
import java.beans.XMLEncoder;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author User
 */
public class XMLCoder {
    public XMLCoder() {}

    public static void encode(Object o, String xmlFileName) {
        try {
            XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(xmlFileName)));

            encoder.writeObject(o);
            encoder.close();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(XMLCoder.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static Object decode(String xml) throws FileNotFoundException {
        XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream(xml)));
        
        Object     object  = decoder.readObject();

        decoder.close();

        return object;
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
